package work.lrl.customer_unbinding;

import cn.hutool.core.util.RandomUtil;
import core.util.ConcurrentUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author Gong.Yang
 */
@Slf4j
public class Demo2 {
    @SneakyThrows
    public static void main(String[] args) {
        List<Runnable> runnableList = new ArrayList<>();
        runnableList.add(() -> {
            int id = RandomUtil.getRandom().nextInt();
            try {
                log.info("开始计算 id->{}", id);
                Thread.sleep(1000);
                log.info("计算结果 id->{}：1", id);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        runnableList.add(() -> {
            int id = RandomUtil.getRandom().nextInt();
            try {
                log.info("开始计算 id->{}", id);
                Thread.sleep(10000);
                log.info("计算结果 id->{}：2", id);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        runnableList.add(() -> {
            int id = RandomUtil.getRandom().nextInt();
            try {
                log.info("开始计算 id->{}", id);
                Thread.sleep(1000);
                log.info("计算结果 id->{}：3", id);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        ConcurrentUtil.commit(runnableList);
        log.info("【并发测试】计算完成");


    }
}
